package cloud.seri.iot.aliyun

import com.aliyuncs.DefaultAcsClient
import com.aliyuncs.exceptions.ClientException
import com.aliyuncs.iot.model.v20180120.*

class DeviceTagsManager(private val client: DefaultAcsClient)
{

    /**
     * 查询指定设备的标签列表
     *
     * @param ProductKey 设备所隶属的产品Key  必须
     * @param DeviceName 设备名称            必须
     *
     * @Des 描述：
     */
    @Throws(ClientException::class)
    fun queryDeviceProp(ProductKey: String, DeviceName: String): QueryDevicePropResponse?
    {
        val request = QueryDevicePropRequest()
        request.deviceName = DeviceName
        request.productKey = ProductKey
        return client.getAcsResponse(request)
    }

    /**
     * 为指定设备设置标签
     *
     * @param ProductKey 设备所隶属的产品Key  必须
     * @param DeviceName 设备名称            必须
     * @param Props 设置的设备标签            必须
     *
     * @Des 描述：
     */
    @Throws(ClientException::class)
    fun saveDeviceProp(ProductKey: String, DeviceName: String, Props: String): SaveDevicePropResponse?
    {

        val request = SaveDevicePropRequest().apply {
            deviceName = DeviceName
            productKey = ProductKey
            props = Props
        }
        return client.getAcsResponse(request)

    }


    /**
     * 删除设备下的指定标签
     *
     * @param ProductKey 设备所隶属的产品Key  必须
     * @param DeviceName 设备名称            必须
     * @param PropKey 设备标签键值            必须
     *
     * @Des 描述：
     */
    @Throws(ClientException::class)
    fun deleteDeviceProp(ProductKey: String, DeviceName: String, PropKey: String): DeleteDevicePropResponse?
    {
        val request = DeleteDevicePropRequest().apply {
            deviceName = DeviceName
            productKey = ProductKey
            propKey = PropKey
        }
        return client.getAcsResponse(request)
    }

}
